import {
    graphql,
    GraphQLSchema,
    GraphQLObjectType,
    GraphQLString,
    GraphQLList,
    GraphQLNonNull,
    GraphQLBoolean,
    GraphQLInt

} from 'graphql';

import Service_provider from '../../db/models/service_provider'

export let service_providerType = new GraphQLObjectType({
    name: 'service_provider',
    fields: {
        id: {
            type: GraphQLInt
        },
        service_provider_name: {
            type: GraphQLString
        },
        repair_personnel: {
            type: GraphQLString
        },
        repair_phone: {
            type: GraphQLString
        }
    }
})

export const service_providerList = {
    type: new GraphQLList(service_providerType),
    args: {},
    resolve(root, params, options) {
        return Service_provider.findAll()
    }
}

export const service_providerOne = {
    type: service_providerType,
    args: {
        id: {
            type: GraphQLInt
        }
    },
    resolve(root, params, options) {
        return Service_provider.findOne({
            where: {
                id: params.id
            }
        })
    }
}
export const service_providerUpdate = {
    type: GraphQLInt,
    args: {
        id: {
            type: GraphQLInt
        },
        service_provider_name: {
            type: GraphQLString
        },
        repair_personnel: {
            type: GraphQLString
        },
        repair_phone: {
            type: GraphQLString
        }
    },
    resolve(root, params, options) {
        return Service_provider.update({
            service_provider_name: params.service_provider_name,
            repair_personnel: params.repair_personnel,
            repair_phone: params.repair_phone
        }, {
            where: {
                id: params.id
            }
        })
    }
}

export const service_providerAdd = {
    type: service_providerType,
    args: {
        service_provider_name: {
            type: GraphQLString
        },
        repair_personnel: {
            type: GraphQLString
        },
        repair_phone: {
            type: GraphQLString
        }
    },
    resolve(root, params, options) {
        return Company.create({
            service_provider_name: params.service_provider_name,
            repair_personnel: params.repair_personnel,
            repair_phone: params.repair_phone
        })
    }
}

export const service_providerDel = {
    type: GraphQLInt,
    args: {
        id: {
            type: GraphQLInt
        }
    },
    resolve(root, params, options) {
        return Service_provider.destroy({
            where: {
                id: params.id
            }
        })
    }
}
